package io.coderyeah.ymcc.web.controller;

import io.coderyeah.ymcc.dto.AlipayNotifyDto;
import io.coderyeah.ymcc.dto.PayDTO;
import io.coderyeah.ymcc.result.JSONResult;
import io.coderyeah.ymcc.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lqs
 * @date 2022/11/4 16:44
 */
@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private IPayService payService;

    // 支付
    @PostMapping("/apply")
    public JSONResult apply(@RequestBody PayDTO payDTO) {
        String html = payService.apply(payDTO);
        return JSONResult.success(html);
    }

    // 异步回调通知
    @RequestMapping("/notify")
    public String notify(AlipayNotifyDto notifyDto) {
        // 回调成功返回 success 失败返回fail
        return payService.notify(notifyDto);
    }
}
